package com.zjy.basic.controller;

import com.zjy.basic.domain.dto.LoginDto;
import com.zjy.basic.domain.dto.WechatBinderDto;
import com.zjy.basic.service.LoginService;
import com.zjy.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private LoginService loginService;

    /**
     * 用户名密码登录
     * @param dto
     * @return
     */
    @PostMapping("/account")
    public AjaxResult account(@RequestBody @Valid LoginDto dto){
        return loginService.account(dto);
    }

    /**
     * 微信登录
     * @param map
     * @return
     */
    @PostMapping("/wechat")
    public AjaxResult wechatLogin(@RequestBody Map<String,String> map){
        return loginService.wechatLogin(map);
    }

    /**
     * 微信绑定
     * @param dto
     * @return
     */
    @PostMapping("/binder")
    public AjaxResult binder(@RequestBody @Valid WechatBinderDto dto){
        return loginService.binder(dto);
    }
}
